package view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class LoginPane extends JPanel{
    ImageIcon img = new ImageIcon("img\\LoginPane.png");
    Frame frame;
    LoginPane(Frame frame){
        this.setVisible(false);
        this.setOpaque(false);
        this.setLayout(null);
        this.addMouseListener(new MouseAdapter() {});
        this.frame = frame;


        JLabel jlUser = new JLabel("用户名");
        jlUser.setForeground(Color.BLACK);
        jlUser.setFont(new Font("楷体", Font.PLAIN,25));
        jlUser.setVisible(true);
        jlUser.setBounds(190,200,100,70);
        this.add(jlUser);

        JLabel jlPass = new JLabel("密  码");
        jlPass.setForeground(Color.BLACK);
        jlPass.setFont(new Font("楷体", Font.PLAIN,25));
        jlPass.setVisible(true);
        jlPass.setBounds(190,300,100,70);
        this.add(jlPass);

        JLabel jlConfirm = new JLabel("确认密码");
        jlConfirm.setForeground(Color.BLACK);
        jlConfirm.setFont(new Font("楷体", Font.PLAIN,25));
        jlConfirm.setVisible(false);
        jlConfirm.setBounds(190,320,100,70);
        this.add(jlConfirm);

        JLabel jlClose = new JLabel(new ImageIcon("img\\Close.png"));
        jlClose.setVisible(true);
        jlClose.setBounds(634,161,45,45);
        jlClose.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                frame.setCursor(Frame.DEFAULT_CURSOR);
                LoginPane.this.setVisible(false);
            }
            @Override
            public void mousePressed(MouseEvent e) {
                frame.setCursor(Frame.HAND_CURSOR);
            }
            @Override
            public void mouseEntered(MouseEvent e) {
                frame.setCursor(Frame.HAND_CURSOR);
            }
            @Override
            public void mouseExited(MouseEvent e) {
                frame.setCursor(Frame.DEFAULT_CURSOR);
            }
        });
        this.add(jlClose);


        JButton jbLogin = new JButton("登 录");
        jbLogin.setBounds(330,420,90,36);
        jbLogin.setVisible(true);
        jbLogin.setFont(new Font("楷体", Font.BOLD,18));
        jbLogin.setFocusPainted(false);
        jbLogin.setBackground(new Color(238, 223, 204));
        this.add(jbLogin);

        JButton jbRegister = new JButton("注 册");
        jbRegister.setBounds(500,420,90,36);
        jbRegister.setVisible(true);
        jbRegister.setFont(new Font("楷体", Font.BOLD,18));
        jbRegister.setFocusPainted(false);
        jbRegister.setBackground(new Color(238, 223, 204));
        this.add(jbRegister);

        JButton jbFinish = new JButton("确 定");
        jbFinish.setBounds(330,420,90,36);
        jbFinish.setVisible(false);
        jbFinish.setFont(new Font("楷体", Font.BOLD,18));
        jbFinish.setFocusPainted(false);
        jbFinish.setBackground(new Color(238, 223, 204));
        this.add(jbFinish);

        JButton jbReturn = new JButton("返 回");
        jbReturn.setBounds(500,420,90,36);
        jbReturn.setVisible(false);
        jbReturn.setFont(new Font("楷体", Font.BOLD,18));
        jbReturn.setFocusPainted(false);
        jbReturn.setBackground(new Color(238, 223, 204));
        this.add(jbReturn);


        JTextField jtUser = new JTextField();
        jtUser.setBounds(310,218,280,35);
        jtUser.setOpaque(false);
        jtUser.setFont(new Font("楷体", Font.BOLD,18));
        jtUser.setVisible(true);
        this.add(jtUser);

        JPasswordField jpPass = new JPasswordField();
        jpPass.setBounds(310,318,280,35);
        jpPass.setOpaque(false);
        jpPass.setVisible(true);
        this.add(jpPass);

        JPasswordField jpConfirm = new JPasswordField();
        jpConfirm.setBounds(310,338,280,35);
        jpConfirm.setOpaque(false);
        jpConfirm.setVisible(false);
        this.add(jpConfirm);

        jbRegister.addActionListener(e -> {
            jlUser.setBounds(190,180,100,70);
            jlPass.setBounds(190,250,100,70);
            jtUser.setBounds(310,198,280,35);
            jpPass.setBounds(310,268,280,35);
            jtUser.setText("");
            jpPass.setText("");
            jpConfirm.setVisible(true);
            jlPass.setText("设置密码");
            jlConfirm.setVisible(true);
            jbRegister.setVisible(false);
            jbLogin.setVisible(false);
            jbReturn.setVisible(true);
            jbFinish.setVisible(true);
        });

        jbReturn.addActionListener(e -> {
            jtUser.setBounds(310,218,280,35);
            jpPass.setBounds(310,318,280,35);
            jlUser.setBounds(190,200,100,70);
            jlPass.setBounds(190,300,100,70);
            jtUser.setText("");
            jpPass.setText("");
            jpConfirm.setText("");
            jpConfirm.setVisible(false);
            jlPass.setText("密  码");
            jlConfirm.setVisible(false);
            jbRegister.setVisible(true);
            jbLogin.setVisible(true);
            jbReturn.setVisible(false);
            jbFinish.setVisible(false);
        });

    }
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.drawImage(img.getImage(),
                (this.getWidth()-img.getIconWidth()) / 2,
                (this.getHeight()-img.getIconHeight()) / 2,
                null);
    }
}
